package jhunter.dao.type;

import java.sql.ResultSet;
import java.sql.SQLException;

public abstract class BaseTypeHandler implements TypeHandler {

	@Override
	public Object getJavaObject(ResultSet rs, String columnName) throws SQLException {
		Object value = getNotNullJavaObject(rs, columnName);
		if (rs.wasNull()) {
			return null;
		}
		return value;
	}

	protected abstract Object getNotNullJavaObject(ResultSet rs, String columnName) throws SQLException;

	@Override
	public Object getSqlObject(Object javaObject) {
		if (javaObject == null) {
			return null;
		}
		return getNotNullSqlObject(javaObject);
	}

	protected Object getNotNullSqlObject(Object javaObject) {
		return javaObject;
	}

}
